package com.laiyizhan.cms.first.controller;

import com.laiyizhan.cms.first.request.FirstRequest;
import com.laiyizhan.cms.first.request.SecondRequest;
import com.laiyizhan.cms.first.service.IFirstService;
import com.laiyizhan.cms.first.service.ISecondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by SoulWolf on 2017/7/19.
 */
@Controller
@RequestMapping("/admin")
public class SecondController {

    @Autowired
    ISecondService secondService;


    /*目录页面*/
    @RequestMapping(value = "/second/index/show")
    public String second_index(SecondRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        modelMap.put("state",secondService.Second_index(request));
        httpSession.setAttribute("number", 1);
        return "/second/index";
    }



    @RequestMapping(value = "/second/a/show")
    public String second_a(FirstRequest request) {
        return "/second/main";
    }
    @RequestMapping(value = "/second/a")
    public String Second_a_record(ModelMap modelMap, SecondRequest request, HttpSession httpSession) {
       String result =  secondService.Second_a(request);
        modelMap.put("state",secondService.Second_index(request));
        if(result=="no"){
            modelMap.put("error","当职称人数不为0的时候，该职称的在职工年人均工资也不能为0");
            modelMap.put("link","/admin/second/a/show");
            return "/error/error";
        }
        return "/second/index";
    }

    @RequestMapping(value = "/second/b/show")
    public String Second_b(FirstRequest request) {
        return "/second/b";
    }
    @RequestMapping(value = "/second/b")
    public String Second_b_record(ModelMap modelMap, SecondRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        secondService.Second_b(request);
        modelMap.put("state",secondService.Second_index(request));
        return "/second/index";
    }

    @RequestMapping(value = "/second/c/show")
    public String Second_c(FirstRequest request) {
        return "/second/c";
    }
    @RequestMapping(value = "/second/c")
    public String Second_c_record(ModelMap modelMap, SecondRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        secondService.Second_c(request);
        modelMap.put("state",secondService.Second_index(request));
        return "/second/index";
    }

    @RequestMapping(value = "/second/d/show")
    public String Second_d(FirstRequest request) {
        return "/second/d";
    }
    @RequestMapping(value = "/second/d")
    public String Second_d_record(ModelMap modelMap, SecondRequest request,HttpSession httpSession) {
        secondService.Second_d(request);
        modelMap.put("state",secondService.Second_index(request));
        request.setoName((String)httpSession.getAttribute("oName"));
        return "/second/index";
    }

    @RequestMapping(value = "/second/e/show")
    public String Second_e(FirstRequest request) {
        return "/second/e";
    }
    @RequestMapping(value = "/second/e")
    public String Second_e_record(ModelMap modelMap, SecondRequest request,HttpSession httpSession) {
        secondService.Second_e(request);
        modelMap.put("state",secondService.Second_index(request));
        request.setoName((String)httpSession.getAttribute("oName"));
        return "/second/index";
    }

    @RequestMapping(value = "/second/f/show")
    public String Second_f() {
        return "/second/f";
    }
    @RequestMapping(value = "/second/f")
    public String Second_f_record(ModelMap modelMap,SecondRequest request,HttpSession httpSession) {
        secondService.Second_f(request);
        modelMap.put("state",secondService.Second_index(request));
        request.setoName((String)httpSession.getAttribute("oName"));
        return "/second/index";
    }


    @RequestMapping(value = "/second/g/show")
    public String second_g() {
        return "/second/g";
    }
    @RequestMapping(value = "/second/g")
    public String second_g_record(ModelMap modelMap,SecondRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        secondService.Second_g(request);
        modelMap.put("state",secondService.Second_index(request));
        return "/second/index";
    }


}
